<template>
    <div class="edit-dialog">
        <edu-dialog
            :title="sendData.title"
            width="50%"
            :visible.sync="show"
            :autoHeight="true"
            :confirmBtnText="$t('common.btn.confirm')"
            :close-on-click-modal="false"
            @close="close"
            @confirm="confirm('studentForm')"
        >
            <el-form
                :model="baseData"
                ref="studentForm"
                :rules="rules"
                label-width="120px"
                label-position="right"
                size="small"
            >
                <el-row>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.studentID')">
                            <el-input v-model="baseData.studentId" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.name')">
                            <el-input v-model="baseData.name" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.sex')">
                            <el-input v-model="baseData.sexI18n" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.birthday')">
                            <el-input v-model="baseData.birthdayStr" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.nation')">
                            <el-input v-model="baseData.nationI18n" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('courseSummary.faculty')">
                            <el-input v-model="baseData.faculty" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('course.majorCode')">
                            <el-input v-model="baseData.profession" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('label.college')">
                            <el-input v-model="baseData.facultyI18n" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.trainingProfessional')">
                            <el-input v-model="baseData.professionI18n" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.IDNumber')">
                            <el-input v-model="baseData.number" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.traininglevel')">
                            <el-input v-model="baseData.trainingLevelI18n" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.enrollmentDate')">
                            <el-input v-model="baseData.enrolDate" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.graduationYear')">
                            <el-input v-model="baseData.graduationDate" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.remark')">
                            <el-tooltip
                                effect="dark"
                                :content="baseData.manualRemark"
                                placement="top-start"
                                :disabled="!baseData.manualRemark || baseData.manualRemark.length < 10"
                            >
                                <el-input v-model="baseData.manualRemark" disabled />
                            </el-tooltip>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.degreeAwarded')">
                            <el-select
                                v-model="baseData.directedDegree"
                                :disabled="canEditConclusion"
                                style="width: 100%"
                            >
                                <el-option
                                    v-for="item in options.directedDegreeOption"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.candidateNumber')">
                            <el-input v-model="baseData.examineeNo" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="毕业类型">
                            <el-select
                                v-model="baseData.manualConclusion"
                                :disabled="canEditConclusion"
                                style="width: 100%"
                            >
                                <el-option
                                    v-for="item in options.manualConclusionOption"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                                <el-option
                                    key="4"
                                    :label="$t('graduationList.permanentClosure')"
                                    value="4"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.isEffective')">
                            <el-select v-model="baseData.isValidity" style="width: 100%">
                                <el-option
                                    v-for="item in options.validityList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="原毕业类型">
                            <el-input v-model="baseData.orginManualConclusionI18n" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item label="不授予学位原因">
                            <el-select v-model="baseData.reasonNotDegree" style="width: 100%">
                                <el-option
                                    v-for="item in options.reasonNotDegreeOption"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.auditBatch')">
                            <el-input
                                :value="newReviewBatch"
                                disabled
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10" :offset="2">
                        <el-form-item :label="$t('graduationList.degreeCertificateNumber')">
                            <el-input v-model="baseData.diplomaNo" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item :label="$t('graduationList.schoolSystem')">
                            <el-input v-model="baseData.lengthSchooling" disabled />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </edu-dialog>
    </div>
</template>
<script>
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
export default {
    props: {
        show: {
            type: Boolean,
            default: false,
        },
        sendData: {
            type: Object,
            default: {},
        },
    },
    data() {
        return {
            rules: {},
            options: {
                directedDegreeOption: [
                    {
                        label: '是',
                        value: '1',
                    },
                    {
                        label: '否',
                        value: '2',
                    },
                ],
                reasonNotDegreeOption: [],
                manualConclusionOption: [],
                validityList: [
                    {
                        value: '0',
                        label: '无效',
                    },
                    {
                        value: '1',
                        label: '有效',
                    },
                ],
            },
        }
    },
    created() {
        const data = {
            lang: this.$store.getters.language || 'cn',
            type: 'allChild',
            keys: ['X_BYJL', 'K_BSYXWYY'],
        }
        queryDic(data).then((res) => {
            if (res.code === 200) {
                UTILS.fillSelect(
                    {
                        manualConclusionOption: 'X_BYJL',
                        reasonNotDegreeOption: 'K_BSYXWYY',
                    },
                    res.data,
                    this.options
                )
            }
        })
    },
    computed: {
        baseData() {
            return this.sendData.data || {}
        },
        canEditConclusion() {
            let flag = false
            if (
                (this.baseData.reviewBatch1 && this.baseData.reviewBatch2) ||
                (!this.baseData.reviewBatch1 && !this.baseData.reviewBatch2)
            ) {
                flag = true
            }
            return flag
        },
        newReviewBatch() {
            let arr = [];
            if (this.baseData.reviewBatch1) {
                arr.push(this.baseData.reviewBatch1);
            }
            if (this.baseData.reviewBatch2) {
                arr.push(this.baseData.reviewBatch2);
            }
            return  arr.join(', ');
        }
    },
    methods: {
        reset() {
            this.$refs.studentForm.resetFields()
        },
        confirm() {
            this.$refs.studentForm.validate((valid) => {
                if (valid) {
                    if (this.sendData.editApi) {
                        this.sendData
                            .editApi({
                                studentId: this.baseData.studentId,
                                directedDegree: this.baseData.directedDegree,
                                manualConclusion: this.baseData.manualConclusion,
                                isValidity: this.baseData.isValidity,
                                reasonNotDegree: this.baseData.reasonNotDegree,
                            })
                            .then((res) => {
                                if (res && res.code === 200) {
                                    this.sendData.updateList()
                                    this.$message({
                                        message: '编辑学生信息成功',
                                        type: 'success',
                                    })
                                    this.close()
                                }
                            })
                    }
                } else {
                    return false
                }
            })
        },
        close() {
            this.$refs.studentForm.resetFields()
            this.$emit('update:show', false)
        },
    },
}
</script>
<style lang="scss" scoped>
    .edit-dialog ::v-deep .el-tooltip.el-input input {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
</style>
